/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vn.ac.c0910g.assignment.DAO;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import vn.ac.c0910g.assignment.Entity.Services;
import vn.ac.c0910g.assignment.Entity.ServicesFacade;

/**
 *
 * @author BachLe
 */
public class ServicesDAO {
    ServicesFacade servicesFacade = lookupServicesFacadeBean();

    public ServicesDAO(){

    }
    private ServicesFacade lookupServicesFacadeBean() {
        try {
            Context c = new InitialContext();
            return (ServicesFacade) c.lookup("java:global/Alluring_Decors/Alluring_Decors-ejb/ServicesFacade!vn.ac.c0910g.assignment.Entity.ServicesFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public List<Services> getAllServices(){
        return this.servicesFacade.findAll();
    }
    public List<Services> getAllServicesbycateid(int Id){
        return this.servicesFacade.findServicesByCategoryId(Id);
    }

    public void addServices(Services s){
        servicesFacade.create(s);
    }

    public void updateServices(Services s){
        servicesFacade.edit(s);
    }

    public void deleteServices(Services s){
        servicesFacade.remove(s);
    }

    public Services findServicesById(String Id){
        return servicesFacade.find(Id);
    }
   
}
